package hander

import (
	"context"
	"fmt"
	"math/rand"
	"rpc-server/basic/global"
	"rpc-server/model"
	__ "rpc-server/proto"
	"time"
)

type UserServer struct {
	__.UnimplementedUserServer
}

func (c *UserServer) SendSms(ctx context.Context, in *__.SendSmsReq) (*__.SendSmsResp, error) {
	i := rand.Intn(9000) + 1000

	global.Rdb.Set(context.Background(), "sendSms"+in.Mobile, i, time.Minute)
	return &__.SendSmsResp{}, nil

}
func (c *UserServer) Login(ctx context.Context, in *__.LoginReq) (*__.LoginResp, error) {
	var user model.User
	if err := global.DB.Where("id = ?").First(&user).Error; err != nil {
		return nil, fmt.Errorf("用户不存在")
	}
	return &__.LoginResp{}, nil

}

func (c *UserServer) Update(ctx context.Context, in *__.UpdateReq) (*__.UpdateResp, error) {
	var user model.Taxi
	if err := global.DB.Updates(&user); err != nil {
		return nil, fmt.Errorf("修改失败")
	}
	return &__.UpdateResp{}, nil
}
